package wwk.common.widget;

import wwk.common.util.LayoutUtil;
import wwk.common.util.ResourceUtil;
import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.ProgressBar;

public class LoadMoreView extends FrameLayout{

	private Button button=null;
	private OnLoadMoreListener loadMoreListener=null;
	private ProgressBar progressBar=null;
	
	public LoadMoreView(Context context) 
	{
		super(context);
		
		init();
	}
	
	public LoadMoreView(Context context, AttributeSet attrs) 
	{
		super(context, attrs);
		
		init();
	}
	
	public LoadMoreView(Context context, AttributeSet attrs, int defStyle) 
	{
		super(context, attrs, defStyle);
		
		init();
	}

	private void init()
	{
		
	}
	
	public void onLoadComplete()
	{
		if(button!=null)
		{
			button.setEnabled(true);
			button.setSelected(false);
			
			progressBar.setVisibility(GONE);
		}
	}
	
	public void setOnLoadMoreListener(OnLoadMoreListener l)
	{
		loadMoreListener=l;
		
		int id=ResourceUtil.getResofR(this.getContext()).getId("loadMoreButton");
		button=(Button)findViewById(id);
		id=ResourceUtil.getResofR(this.getContext()).getId("progressBar");
		progressBar=(ProgressBar)findViewById(id);
		
		button.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View arg0) 
			{
				button.setSelected(true);
				button.setEnabled(false);
				
				progressBar.setVisibility(VISIBLE);
				
				if(loadMoreListener!=null)
				{
					loadMoreListener.onLoadMoreClicked();
				}
			}
		});
	}
}
